<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
    <title>_异动单管理</title>
    
	
	<script type="text/javascript">
		var tables_stockChangeBill = null;
		$(function(){
			//初始化dataTables-plan
	        tables_stockChangeBill=$("#table_stockChangeBill").dataTable({
	           "bServerSide":true,
	           "sAjaxSource":'${ctx}/stockChangeBill/queryStockChange',
	           "fnServerData": retrieveData_stockChangeBill,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	            "aoColumns": [
					{"mData": 'customerCode'},
					{"mData": 'warehouseCode'},
					{"mData": 'orderType',"render": function (data, type, full) {
						var orderType = (full.orderType=="INSTORAGE"?"入库单":"销售订单")
                        var display=orderType+"("+full.orderCode+")";
                        return display;
                     }},
					{"mData": 'quantity'},
					{"mData": 'remark'},
					{"mData": 'createTime',"render": function (data, type, full) {
                        var time=full.createTime.time;
                        if(!time)return"";
                        var date = new Date(time);
                        return date.Format("yyyy-MM-dd");
                     }},
					{"mData": 'createBy'},
// 					{"mData": 'status',"render": function (data, type, full) {
//                         var statusStr = (full.status=='send'?'已推送':'未推送');
//                         return statusStr;
//                      }},
					{"mData": 'id',"render": function (data, type, full) {
						var str = '已推送';
						var id=full.id;
						if(full.status!='send'){
							str = '<a href="#configWindow" onclick="toSaveStockChangeBill('+id+');" role="button"  class="btn btn-primary" data-toggle="modal">修改</a>&nbsp;';
							str += '<a href="#configWindow" onclick="sendQmStockChange('+id+');" role="button"  class="btn btn-primary" data-toggle="modal">推送奇门</a>&nbsp;';
							str += '<button class="btn btn-danger" onclick="delRow('+id+')" type="button">删除</button>';
						}
                        return str;
                     }}
	           ]
	        });
		});
		function delRow(id){
			jConfirm("确定删除配置信息?","温馨提醒",function(result){
		    	if(result){
					$.ajax({
						type:'post',
						url:'${ctx}/stockChangeBill/deleteStockChangeBill',
						data:{
							id:id
						},
						dataType:'json',
						success:function(data) {
							var msg=data.msg;
							if(msg=='success'){
								jAlert("删除成功!","温馨提示",function(){
									tables_stockChangeBill.fnDraw();
								});
							}else{
								jAlert("删除失败!","温馨提示",function(){
									tables_stockChangeBill.fnDraw();
								});
							}
						},
						error:function() {
							alert("网络繁忙，请稍后重试...");
						}
			       });
	    		}
	      	});
		}
		
		function sendQmStockChange(id){
			jConfirm("确定推送异动单?","温馨提醒",function(result){
		    	if(result){
					$.ajax({
						type:'post',
						url:'${ctx}/stockChangeBill/v2_sendQmStockChange',
						data:{
							id:id
						},
						dataType:'json',
						success:function(data) {
							var msg=data.msg;
							if(msg=='success'){
								jAlert("推送成功!","温馨提示",function(){
									tables_stockChangeBill.fnDraw();
								});
							}else{
								jAlert(data.content,"温馨提示",function(){
									tables_stockChangeBill.fnDraw();
								});
							}
						},
						error:function() {
							alert("网络繁忙，请稍后重试...");
						}
			       });
	    		}
	      	});
		}
		
		function retrieveData_stockChangeBill(sSource, aoData, fnCallback){
			//查询参数
		   var customerCode=$("#customerCode").val();
		   aoData.push( { "name": "customerCode", "value": customerCode } );  
		    
		   var warehouseCode=$("#warehouseCode").val();
		   aoData.push( { "name": "warehouseCode", "value": warehouseCode } );
		   
		   
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData),
		       "success": function(resp) {  
	       			fnCallback(resp);
	       		}
		   }); 
		}
		
		function query() {
			tables_stockChangeBill.fnDraw();
		}
		
		 function toSaveStockChangeBill(id){
			 if(!id)id="";
			 $("#queryForm").attr("action","${ctx}/stockChangeBill/v2_toSaveStockChangeBillPage?id="+id);
		     $("#queryForm").submit();
		  }
		 
    </script>
</head>

<body>
<div id="fullbg"></div>
<div id="dialog">
	<div>
		<img src="${ctx}/static/022.gif"></img>
	</div>
</div>
<section class="content">
    <!-- 查询条件  start-->
   	<div class="row">
	<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary" >
			    
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
				</div>
				
				<div class="box-body">
				    <form class="form-search" id="queryForm" method="post" action="${ctx}/stockChangeBill/findstockChangeBill" style="margin-top: 10px;">
					    <!-- 第一行 -->
						<div class="form-group row">
							<div class="col-sm-3">
								<div class="input-group col-sm-12">
									<span class="input-group-text"> 商家名称： </span> 
									<select class="form-control" id="customerCode" name="customerCode" onchange="ajaxAreaGroup(this,'warehouseCode')">
										<option value=""></option>
										<c:forEach items="${customerList}" var="customer">
											<option value="${customer.customerCode}"
												<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>>${customer.customerName}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							
							<div class="col-sm-3">
								<div class="input-group col-sm-12">
									<span class="input-group-text"> 仓库： </span> 
									<select class="form-control" id="warehouseCode" name="warehouseCode" >
										<option value=""></option>
										<c:forEach items="${warehouseList}" var="warehouse">
											<option value="${warehouse.groupCode}"
												<c:if test="${warehouseCode eq warehouse.groupCode}">selected=selected</c:if>>${warehouse.groupName}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							
							
						</div>
						<div class="form-group row">
							<div class="col-sm-6">
								<button class="btn btn-info" type="button" onclick="query();">搜索</button>
								<button class="btn btn-info" type="button" style="margin-left: 10px;" onclick="toSaveStockChangeBill();">添加库存异动</button>
							</div>
						</div>
					</form>
				</div>

			</div>

	 </div>
	</div>
    <!-- 查询条件 end -->
    
    <!-- 查询结果 start -->
	<div class="form-group row" >
		<div class="col-md-12">
	       <div class="box box-primary">
				 <div class="box-header"></div>
				 <div class="box-body table-responsive">
				     <table id="table_stockChangeBill" class="table table-bordered table-striped">
				         <thead>
				             <tr>
				                <th style="width: 80px;">商家编码</th>
							    <th style="width: 80px;">仓库编码</th>
							    <th style="width: 140px;">单据类型(相关单号)</th>
							    <th style="width: 60px;">异动数量</th>
							    <th style="width: 100px;">备注</th>
								<th style="width: 60px;">创建时间</th>
								<th style="width: 80px;">创建人</th>
								<th style="width: 80px;">操作</th>
				             </tr>
				         </thead>
				     </table>
				 </div>
			 </div>
		
		</div>
	</div>
	
	
	
</section>     
</body>
</html>
